﻿using System;
using System.Collections.Generic;
namespace Program12
{
    class Program
    {
        static void Main(string[] args)
        {
            var list = GetFullPermutation(3);
        }

        // 获取全排列
        public static List<List<int>> GetFullPermutation(int n)
        {
            List<List<int>> result = new List<List<int>>();
            List<int> listRest = GetInputNums(n);
            List<int> listNow = new List<int>();
            GetFPItem(listNow, listRest, result);
            return result;
        }

        // 获取1-n的数组
        public static List<int> GetInputNums(int n)
        {
            List<int> inputNum = new List<int>();
            for (int i = 1; i <= n; i++)
            {
                inputNum.Add(i);
            }
            return inputNum;
        }

        //获取全排列的每一个item
        public static void GetFPItem(List<int> listNow, List<int> listRest, List<List<int>> result)
        {
            if (listRest.Count == 0)
            {
                result.Add(listNow);
                return;
            }
            for (int i = 0; i < listRest.Count; i++)
            {
                List<int> newListNow = new List<int>();
                listNow.ForEach(item => newListNow.Add(item));
                newListNow.Add(listRest[i]);
                List<int> newListRest = new List<int>();
                listRest.ForEach(item =>
                {
                    if (item != listRest[i])
                        newListRest.Add(item);
                });
                GetFPItem(newListNow, newListRest, result);
            }
        }
    }
}
